home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / aprs75c / simulate.bas < prev    next >
BASIC Source File  |  1996-03-15  |  5KB  |  134 lines

  1. i = 99
  2. DIM UT(i), UP(i), SUX(i)
  3. SCREEN 9
  4. WIDTH 80, 43
  5. delay = 500
  6. QU = 10      'Quantum time units per second
  7. NU = 40      'Number of UNITS
  8. PEi = 30     'Packet Period
  9. PLi = 1      'Packet Length
  10. TTi = 480    'Total TIme
  11. DO
  12. CLS
  13. PRINT "APRS UNPROTO Packet Simulator Program,  SIMULATE.bas version 1.0"
  14. PRINT
  15. PRINT
  16. PRINT
  17. PRINT "This program simulates the performance of a given number of Packet units on"
  18. PRINT "a simplex packet channel with no digipeater.  The preformance criteria are:"
  19. PRINT
  20. PRINT "  Number of units"
  21. PRINT "  Nominal period between packets (PER = PER + RND(x)"
  22. PRINT "  Packet Length"
  23. PRINT "  Total time of simulation"
  24. PRINT
  25. PRINT "The numeric data show the STATION number, the TIME of the next transmission"
  26. PRINT "and the current PERIOD in seconds.  If you choose more than 40 stations, this"
  27. PRINT "data will not fit on the screen, so it is not displayed..."
  28. PRINT
  29. PRINT "SIMULATE.bas displays the number of stations vertically, and the number of"
  30. PRINT "packets transmitted horizontally.  The BLUE boxes represent packets"
  31. PRINT "transmitted.  If the packet is successful without collisions, then a GREEN"
  32. PRINT "green box is added to that row and the packet turns yellow."
  33. PRINT
  34. PRINT "If all the rows turn green in the given time period, then you have 100%"
  35. PRINT "communication success.  When 100% is reached, the simulation stops, otherwise"
  36. PRINT "it runs for the given time period.  The number of green boxes per row,"
  37. PRINT "shows the redundancy required to achieve that measure of success.  "
  38. PRINT
  39. PRINT "Run the simulation several times for your chosen project.  The results will"
  40. PRINT "be different each time, but will tend to indicate an overall performance."
  41. PRINT
  42. PRINT "WARNING:  This program is based on TWO specific assumptions:"
  43. PRINT ""
  44. PRINT "   1)  That stations BEGIN transmitting randomly within the given PERIOD."
  45. PRINT "   2)  It assumes ONLY one form of RETRY PERIODICITY calculation."
  46. PRINT
  47. PRINT "EXTRAPOLATING these results to any other conditions may yield SIGNIFICANTLY"
  48. PRINT "different results!"
  49. PRINT
  50. PRINT
  51. PRINT "Enter all times in seconds"
  52. PRINT
  53. PRINT
  54. PRINT "Enter number of units or Q to quit.  ("; NU; ")"; : INPUT a$
  55. PRINT : IF a$ <> "" THEN NU = VAL(a$)
  56. PRINT "Enter nominal packet period ("; PEi; ")"; : INPUT a$
  57. PRINT : IF a$ <> "" THEN PEi = VAL(a$)
  58. PRINT "Enter Packet Length in Seconds ("; PLi; ")"; : INPUT a$
  59. PRINT : IF a$ <> "" THEN PLi = VAL(a$)
  60. PRINT "Enter Total time of simulation ("; TTi; ")"; : INPUT a$
  61. PRINT : IF a$ <> "" THEN TTi = VAL(a$)
  62. PE = PEi * QU           'Convert all time units to quantum units
  63. PL = PLi * QU
  64. TT = TTi * QU
  65. TS = INT(TT / 502) + 1                     'Time Scale Horizontal
  66. SV = INT(350 / NU): IF SV > 8 THEN SV = 8  'Scale Factor Vertical
  67. CLS : T = 0: pct = 0: All = 0
  68. PRINT "STN TIME PRD GOOD   STATIONS ="; NU; "  PERIOD ="; PEi; "  LENGTH ="; PLi; "       TIME ="
  69. LOCATE 43, 1: PRINT "Hit S for Slower, F for Faster, Space Bar to PAUSE, and Q to Quit......";
  70. LOCATE 2, 1
  71. FOR i = 1 TO NU:
  72.     UT(i) = INT(PE * RND(i)): REM j = RND(i)
  73.     UP(i) = PE
  74.     SUX(i) = 0
  75.     IF NU < 43 THEN GOSUB PrintI
  76. NEXT i: LINE (138, 1 * SV)-(138, (NU + 1) * SV), 14
  77. TX = 0: JE = 0
  78. DO UNTIL T = TT + 1 OR All
  79.    LOCATE 1, 1
  80.    T = T + 1
  81.    LOCATE 1, 75: PRINT INT(T / QU)
  82.    None = -1
  83.    FOR i = 1 TO NU
  84.        IF T >= UT(i) THEN         'It is transmitting
  85.           None = 0
  86.           LINE (138 + T / TS, i * SV)-(138 + T / TS, (i + 1) * SV), 9
  87.           IF TX = 0 THEN TB = T
  88.           IF TX = 0 OR TX = i THEN TX = i ELSE TX = 9999: TB = 0
  89.           IF T >= UT(i) + PL THEN 'Time to stop packet
  90.              UP(i) = UP(i) + INT(PE * RND(TIMER))
  91.              REM UP(i) = PE + INT(PE * RND(TIMER))
  92.              UT(i) = UT(i) + UP(i)
  93.              JE = i
  94.              IF NU < 43 THEN LOCATE i + 1, 1: GOSUB PrintI
  95.           END IF
  96.        END IF
  97.    NEXT i
  98.    IF JE AND TX = JE THEN
  99.       SOUND 3000, .1
  100.       REM The one ending is the same as the one beginning
  101.       LINE (138 + TB / TS, TX * SV)-(138 + T / TS, (TX + 1) * SV), 14, BF
  102.       SUX(JE) = SUX(JE) + 1
  103.       All = -1
  104.       FOR j = 1 TO NU
  105.           LINE (106, SV * j)-(106 + 5 * SUX(j), SV * (j + 1) - 1), 10, BF
  106.           IF SUX(j) = 0 THEN All = 0
  107.       NEXT j
  108.       TX = 0
  109.    
  110.    END IF
  111.    IF None THEN TX = 0
  112.    a$ = INKEY$
  113.    IF a$ = " " THEN DO UNTIL INKEY$ <> "": LOOP
  114.    IF UCASE$(a$) = "F" THEN delay = delay / 2: IF delay < 10 THEN delay = 10
  115.    IF UCASE$(a$) = "S" THEN delay = delay * 2
  116.    IF UCASE$(a$) = "Q" THEN EXIT DO
  117.    FOR i = 1 TO delay: a = a + a + a + a + a: NEXT i
  118. LOOP
  119. FOR i = 1 TO NU
  120.     IF SUX(i) THEN pct = pct + 1
  121. NEXT i
  122. LOCATE 42, 1: PRINT "Success rate"; INT(100 * pct / NU); "%";
  123. LOCATE 43, 1: PRINT "in "; INT(T / QU); " seconds.";
  124. IF All THEN LINE (0, 324)-(150, 349), 12, B
  125. LOCATE 43, 17: PRINT SPACE$(18);
  126. INPUT "Hit ENTER for another run, or Q to quit"; a$
  127. IF UCASE$(a$) = "Q" THEN EXIT DO
  128. LOOP
  129. SYSTEM
  130.  
  131. PrintI: PRINT MID$(STR$(i), 2); TAB(4); INT(UT(i) / QU); TAB(9); INT(UP(i) / QU)
  132.         RETURN
  133.  
  134.